	$(function(){
		$.fn.zTree.init($("#fatherIdzTree"),{	
				async:{//异步加载
					enable: true,//开启异步提交
					type: "POST",
					autoParam: ["id"],//自动提交父节点Id
					url: base+"/power/getDatazTree"
				},
				view: {//显示设置
					dblClickExpand: false
				},
				data: {//数据字段属性等设置
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "fatherId",
						rootPId: 0
					},
					key: {
						checked:"powerName",
						name:"powerName",
						url:"powerLine"
					}
				},
				callback: {//处理事件
					onClick: onClick
				}
		});
		//提交表单
		$("#updPower").click(function(){
			$("#frm").submit();
		});
		//校验
		$("#frm").validate({
			//验证通过提交表单
			submitHandler:function(form){
				$("#updPower").button('loading');//提交时屏蔽多次点击
				 $.post(base+"/power/upd",$("#frm").serialize(),function(data){
					 $("#updPower").button('reset');//重置提交按钮 
					 gDialog.fClose();
					 var $table=window.frames["centerIframe"].$('#resultTable');
					 if(data=="succeed"){//修改成功
						 //获取data层框架对象
						 $table.bootstrapTable('refresh',{url:base+"/power/getData"});
						message_box.show('<h4>成功</h4>修改成功!','success');
					 }else{
						message_box.show('<h4>失败</h4>'+data,"error");
					 }
				},"text");
			},
		     rules: {
		    	 "power.powerName": {
		    	    required: true
		    	 },
		    	 "power.powerCode": {
			    	required: true,
		    	    remote:{//远程验证权限代码是否已存在
		    	        url:base+"/power/isExistPowerCode",
		    	        type: "post",               //数据发送方式
		    	        dataType: "json",            //接受数据格式   
		    	        data: {                     //要传递的数据
			    			 id:function() {
			    				 return $("#id").val();
			    			 }
			    		}
		    	    }
			     },
			     "power.url": {
			    	 required: true
			     },
			     "power.iconCls": {
			    	 required: true
			     },
		    	 "power.position": {
			    	required: true
			     },
			     "power.seq": {
			    	 required:true,
			    	 digits:true
			     }
		    },
		     messages: {
		    	 "power.powerName": {
		    	   required: "* 请输入权限名称!"
		    	 },
		    	 "power.powerCode": {
		    		 required: "* 请输入权限代码!",
		    		 remote: "* 权限已存在!"
		    	 },
		    	 "power.url": {
		    		 required: "* 请输入权限URL!"
		    	 },
		    	 "power.iconCls": {
		    		 required: "* 请输入图片类!"
		    	 },
		    	 "power.position": {
		    		 required: "* 请选择菜单位置"
		    	 },
		    	 "power.seq": {
		    		 required:"* 必须输入数字",
		    		 digits: "* 只能输入数字"
		    	 }
		    },
		    errorPlacement:function(error, element) {//错误显示位置
		    },
		    highlight: function(element, errorClass) {//验证不通过处理事件
		    	$(element).parent().parent().removeClass("has-success");
		    	$(element).parent().parent().addClass("has-error");
		    },
		    unhighlight: function(element, errorClass) {//验证通过
		    	$(element).parent().parent().removeClass("has-error");
		    	$(element).parent().parent().addClass("has-success");
		    }
		});
	});
	function onClick(e,treeId,treeNode){
		var zTree = $.fn.zTree.getZTreeObj("fatherIdzTree"),
		nodes = zTree.getSelectedNodes(),
		text = "",value="";
		nodes.sort(function compare(a,b){return a.id-b.id;});
		for (var i=0, l=nodes.length; i<l; i++) {
			text += nodes[i].powerName + ",";
			value+= nodes[i].id + ",";
		}
		if (text.length > 0 ){
			text = text.substring(0, text.length-1);
			value = value.substring(0, value.length-1);
		}
		$("#fatherId").attr("value", text);//设置显示的值
		$("#fatherIdVal").attr("value", value);//设置后台获取的值
	}
	function showMenu() {
		$("#fatherIdzTree").parent().slideDown("slow");//淡入
		$("body").bind("mousedown", onBodyDown);//绑定
	}
	function hideMenu() {
		$("#fatherIdzTree").parent().slideUp("slow");//淡出
		$("body").unbind("mousedown", onBodyDown);//取消绑定
	}
	function onBodyDown(event) {
		if (!(event.target.id == "fatherIdzTreeBut" || event.target.id == "fatherIdzTree" || $(event.target).parents("#fatherIdzTree").length>0)) {
			hideMenu();
		}
	}